package com.xposed.openfire.smack;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.xposed.openfire.smack.entity.DaoMaster;
import com.xposed.openfire.smack.entity.DaoSession;
import com.xposed.openfire.smack.entity.UserList;
import com.xposed.openfire.smack.xmpp.XmppConnection;

import org.jxmpp.jid.EntityFullJid;

import java.util.List;

public class APPOpenfireSmack extends Application {

    private static Context mContext;
    private static EntityFullJid entityFullJid;
    private static DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        setDatabase();

        XmppConnection.getInstance().openConnection();
    }

    public static Context getContext() {
        return mContext;
    }

    public static void setContext(Context mContext) {
        APPOpenfireSmack.mContext = mContext;
    }

    public static EntityFullJid getEntityFullJid() {
        return entityFullJid;
    }

    public static void setEntityFullJid(EntityFullJid entityFullJid) {
        APPOpenfireSmack.entityFullJid = entityFullJid;
    }

    private void setDatabase() {
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "smack.db", null);
        SQLiteDatabase db = helper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
    }

    public static DaoSession getDaoSession() {
        return daoSession;
    }
}
